package com.yanmaohu.yulia.bean;

/**
 * @author Bright Lee
 */
public final class ReferencesSpecification implements ColumnConstraint {

    private int beginIndex;
    private int endIndex;
    private ReferencedTableAndColumns referencedTableAndColumns;
    private MatchType matchType;
    private ReferentialTriggeredAction referentialTriggeredAction;

    public ReferencesSpecification(int beginIndex,
                                   ReferencedTableAndColumns referencedTableAndColumns,
                                   MatchType matchType,
                                   ReferentialTriggeredAction referentialTriggeredAction) {
        this.beginIndex = beginIndex;
        this.endIndex = endIndex; // TODO
        if (referentialTriggeredAction != null) {
            this.endIndex = referentialTriggeredAction.getEndIndex();
        } else if (matchType != null) {
            this.endIndex = matchType.getEndIndex();
        } else {
            this.endIndex = referencedTableAndColumns.getEndIndex();
        }
        this.referencedTableAndColumns = referencedTableAndColumns;
        this.matchType = matchType;
        this.referentialTriggeredAction = referentialTriggeredAction;
    }

    public int getBeginIndex() {
        return beginIndex;
    }

    public int getEndIndex() {
        return endIndex;
    }

    public ReferencedTableAndColumns getReferencedTableAndColumns() {
        return referencedTableAndColumns;
    }

    public MatchType getMatchType() {
        return matchType;
    }

    public ReferentialTriggeredAction getReferentialTriggeredAction() {
        return referentialTriggeredAction;
    }

}
